package dao.impl;

import bean.Order;
import bean.OrderItem;
import bean.Product;
import dao.BaseDao;
import dao.OrderDao;
import dao.OrderItemDao;

import java.util.ArrayList;

public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {
    @Override
    public int insert(OrderItem order) {
        String sql = "INSERT INTO `t_order_item` (`name`,`price`,`category`,`pnum`,`imgurl`,`description`)VALUES(?,?,?,?,?,?)";
        return update(sql);
    }

    @Override
    public int delete(Integer id) {
        String sql = "DELETE FROM `t_order_item` WHERE `id`=?";
        return update(sql,id);
    }

    @Override
    public int update(OrderItem order) {
        String sql = "UPDATE `t_order_item` SET `name`=?,`price`=?,`category`=?,`pnum`=?,`imgurl`=?,`description`=? WHERE `id`=?";
        return update(sql);
    }

    @Override
    public OrderItem queryById(Integer id) {
        String sql = "SELECT * FROM `t_order_item` WHERE `id`=?";
        return queryForOne(OrderItem.class,sql,id);
    }

    @Override
    public ArrayList<OrderItem> queryAll() {
        String sql = "SELECT * FROM `t_order_item`";
        return queryForList(OrderItem.class,sql);
    }
}
